#include "tcp_server.hpp"
#include "daemon.hpp"
#include <memory>
#include <algorithm>

using namespace ns_server;

static void usage(std::string proc)
{
    std::cout << "Usage:\n\t" << proc << " port\n"
              << std::endl;
}

std::string transactionString(std::string message)
{
    // 将数据中的小写字母转为大写字母
    std::string mes = message;
    transform(mes.begin(), mes.end(), mes.begin(), ::toupper);
    return mes;
}

int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        usage(argv[0]);
        exit(USAGE_ERR);
    }

    std::unique_ptr<TcpServer> tsvr(new TcpServer(transactionString, atoi(argv[1])));
    tsvr->InitServer();
    Deamon();//让服务器变成守护进程
    tsvr->Start();

    return 0;
}